/**
 * 部门管理初始化
 */
var Customer = {
    id: "CustomerTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}

/**
 * 初始化表格的列
 */
Customer.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: '病历号', field: 'medicalRecordNumber', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<a href='javascript:;' style='color: red' onclick='Customer.openBilee(" + '"' + row.id + '"' + ")'>" + row.customerName + "</a>"
                } else {
                    return "<a href='javascript:;' onclick='Customer.openBilee(" + '"' + row.id + '"' + ")'>" + row.customerName + "</a>"
                }

            }
        },
        // {title: '化名', field: 'pseudonym', align: 'center', valign: 'middle', sortable: true,},
        {title: '电话', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true, width: 135,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value + "</span>"
                } else {
                    return value;
                }
            }},
        {title: '使用人', field: 'phoneSharShip', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '性别', field: 'customerSex', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    if (value == 1) {
                        return "<span style='color: red'>男</span>";
                    } else if (value == 2) {
                        return "<span style='color: red'>女</span>";
                    } else {
                        return "<span style='color: red'>未知</span>";
                    }
                }else {
                    if (value == 1) {
                        return "男";
                    } else if (value == 2) {
                        return "女"
                    } else {
                        return "未知"
                    }
                }

            }
        },
        {title: '年龄', field: 'customerAge', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        // {title: '生日', field: 'birthday', align: 'center', valign: 'middle', sortable: true, width: '17%',},
        {title: '咨询项目', field: 'appointmentPayService', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                var reg = /,/g;
                if (value == "" || value == null) {
                    if(row.accountArrears > 0){
                        return "<a href='javascript:;' style='color: red' onclick='Customer.choiceAppointment(" + '"' + row.id + '"' + ")'>[请选择]</a>"
                    }else {
                        return "<a href='javascript:;' onclick='Customer.choiceAppointment(" + '"' + row.id + '"' + ")'>[请选择]</a>"
                    }
                } else {
                   if(row.accountArrears > 0){
                       return "<a href='javascript:;' style='color: red' onclick='Customer.choiceAppointment(" + '"' + row.id + '"' + ")'>" + value.replace(reg, ' ') + "</a>"
                   }else {
                       return "<a href='javascript:;' onclick='Customer.choiceAppointment(" + '"' + row.id + '"' + ")'>" + value.replace(reg, ' ') + "</a>"
                   }
                }
            }
        },
        {title: '一级渠道', field: 'oneChannel', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {title: '二级渠道', field: 'twoChannel', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {title: '三级渠道', field: 'thrChannel', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {
            title: '客户状态旧', field: 'customerStatus',  align: 'center', valign: 'middle',width: 120,
            formatter: function (value, row, index) {
                if (value == "作废") {
                    if(row.accountArrears > 0){
                        return "<a href='javascript:;' style='color: red;' onclick='Customer.ToVoidDetails(" + '"' + row.id + '"' + ")'>[作废]</a>"
                    }else {
                        return "<a href='javascript:;' onclick='Customer.ToVoidDetails(" + '"' + row.id + '"' + ")'>[作废]</a>"
                    }
                } else {
                    if(row.accountArrears > 0){
                        return "<span style='color: red'>"+value+"</span>";
                    }else {
                        return value;
                    }
                }
            }
        },
        {
            title: '客户状态', field: 'xcustomerStatus', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (value == "作废") {
                    if(row.accountArrears > 0){
                        return "<a href='javascript:;' style='color: red;' onclick='Customer.ToVoidDetails(" + '"' + row.id + '"' + ")'>[作废]</a>"
                    }else {
                        return "<a href='javascript:;' onclick='Customer.ToVoidDetails(" + '"' + row.id + '"' + ")'>[作废]</a>"
                    }
                } else {
                    if(row.accountArrears > 0){
                        return "<span style='color: red'>"+value+"</span>";
                    }else {
                        return value;
                    }
                }
            }
        },
        {
            title: '成交状态', field: 'dealStatus', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (value == "已成交") {
                    if(row.accountArrears > 0){
                        return "<a href='javascript:;' style='color: red' onclick='Customer.opendealStatus(" + '"' + row.reservationsId + '"' + ")'>[已成交]</a>"
                    }else {
                        return "<a href='javascript:;' onclick='Customer.opendealStatus(" + '"' + row.reservationsId + '"' + ")'>[已成交]</a>"
                    }
                } else if (value != "已成交") {
                    if(row.accountArrears > 0){
                        return "<span style='color: red'>未成交</span>";
                    }else {
                        return "未成交";
                    }
                }
            }
        },
        {
            title: '缴费金额', field: 'actualAccountBalance', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<a href='javascript:;' style='color: red' onclick='Customer.reviseAccountBalance(" + '"' + row.reservationsId + '","' + row.actualAccountBalance + '"' + ")'>" + row.actualAccountBalance + "</a>"
                }else {
                    return "<a href='javascript:;' onclick='Customer.reviseAccountBalance(" + '"' + row.reservationsId + '","' + row.actualAccountBalance + '"' + ")'>" + row.actualAccountBalance + "</a>"
                }
            }
        },
        // {title: '赠送余额', field: 'giveAccountBalance', align: 'center', valign: 'middle', sortable: true},
        {
            title: '欠费', field: 'accountArrears', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<a href='javascript:;' style='color: red' onclick='Customer.reviseArrears(" + '"' + row.reservationsId + '","' + row.accountArrears + '"' + ")'>" + row.accountArrears + "</a>"
                }else {
                    return "<a href='javascript:;' onclick='Customer.reviseArrears(" + '"' + row.reservationsId + '","' + row.accountArrears + '"' + ")'>" + row.accountArrears + "</a>"
                }
            }
        },
        {
            title: '现场TC', field: 'fieldTc', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if (value == "" || value == null) {
                    if(row.accountArrears > 0){
                        return "<a href='javascript:;' style='color: red' onclick='Customer.choiceTc(" + '"' + row.id + '"' + ")'>[请选择]</a>"
                    }else {
                        return "<a href='javascript:;' onclick='Customer.choiceTc(" + '"' + row.id + '"' + ")'>[请选择]</a>"
                    }
                } else {
                    if(row.accountArrears > 0){
                        return "<a href='javascript:;' style='color: red' onclick='Customer.choiceTc(" + '"' + row.id + '"' + ")'>" + value + "</a>"
                    }else {
                        return "<a href='javascript:;' onclick='Customer.choiceTc(" + '"' + row.id + '"' + ")'>" + value + "</a>"
                    }
                }
            }
        },
        {
            title: '医生', field: 'doctor', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                var reg = /,/g;
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value.replace(reg, ' ') + "</span>"
                } else {
                    return value.replace(reg, ' ');
                }
            }
        },
        {
            title: '医助/护士', field: 'nurse', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                var reg = /,/g;
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value.replace(reg, ' ') + "</span>"
                } else {
                    return value.replace(reg, ' ');
                }
            }
        },
        {
            title: '到店时间', field: 'arrivalTime', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<span style='color: red'>"+value.substring(0, 19)+"</span>";
                }else {
                    return value.substring(0, 19);
                }
            }
        },
        {
            title: '初诊时间', field: 'firstVisitDate', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true, width: 120,
            formatter: function (value, row, index) {
                if(row.accountArrears > 0){
                    return "<span style='color: red'>" + value + "</span>"
                } else {
                    return value;
                }
            }
        },
    ]
    return columns;
};


Customer.openRevisit = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '成交操作',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/openRevisit/' + reservationsId
    });
    this.layerIndex = index;
};

Customer.choiceTc = function (id) {
    var index = layer.open({
        type: 2,
        title: '选择Tc',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_choiceTc/' + id
    });
    this.layerIndex = index;
};

Customer.choiceAppointment = function (id) {
    var index = layer.open({
        type: 2,
        title: '选择咨询项目',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_choiceAppointment/' + id
    });
    this.layerIndex = index;
};

Customer.opendealStatus = function (id) {
    $.ajax({
        url: Feng.ctxPath + "/reservations/getTotleMoneys",
        type: "post",
        data: {
            "id": id
        },
        success: function (data) {
            alert("成交金额：" + data + "元");
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
};


/**
 * 点击发短信
 */
Customer.msgSend = function () {
    var customerId = document.getElementById("customerId").value;
    var customerName = document.getElementById("customerName").value;
    var customerPhone = document.getElementById("customerPhone").value;
    var messageContent = document.getElementById("message_content").value;
    var outpatientName = $("#outpatientName").val();
    var address = $("#address").val();
    var phone = $("#phone").val();
    var templateCode = "SMS_151575458";
    if (confirm("发送信息给【" + customerName + "】?")) {
        $.ajax({
            url: Feng.ctxPath + "/msgSend/msgSend",
            type: "post",
            data: {
                customerId: customerId,
                messageContent: messageContent,
                templateCode:templateCode,
                customerPhone: customerPhone,
                outpatientName:outpatientName,
                address:address,
                phone:phone,
                customerName:customerName
            },
            success: function (data) {
                Feng.success('操作成功!');
                Customer.close();
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};

Customer.openBilee = function (ide) {
    var index = layer.open({
        type: 2,
        title: '到店客户详情',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_openBileLists/' + ide
    });
    this.layerIndex = index;
};

Customer.reviseArrears = function (id, accountArrears) {
    var ia = id + "," + accountArrears;
    var index = layer.open({
        type: 2,
        title: '修改欠费',
        area: ['60%', '40%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_accountArrears/' + ia
    });
    this.layerIndex = index;
};

Customer.reviseAccountBalance = function (id, actualAccountBalance) {
    var ia = id + "," + actualAccountBalance;
    var index = layer.open({
        type: 2,
        title: '修改缴费',
        area: ['60%', '40%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_actualAccountBalance/' + ia
    });
    this.layerIndex = index;
};

Customer.ToVoidDetails = function (id) {
    var index = layer.open({
        type: 2,
        title: '添加回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/toVoidDetails/' + id
    });
    this.layerIndex = index;
};

Customer.openAddVisited = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '添加回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_addVisited/' + reservationsId
    });
    this.layerIndex = index;
};

Customer.openRecharge = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '添加充值',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/recharge/to_recharge/' + Customer.seItem.id
        });
        this.layerIndex = index;
    }
};

Customer.specialSupplement = function () {
    if (this.check()) {
        var reservationsId = Customer.seItem.reservationsId;
        var customerId = Customer.seItem.id;
        var rc = reservationsId + "," + customerId;
        var index = layer.open({
            type: 2,
            title: '特殊补款',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/recharge/to_specialSupplement/' + rc
        });
        this.layerIndex = index;
    }
};

Customer.specialRefund = function () {
    if (this.check()) {
        var reservationsId = Customer.seItem.reservationsId;
        var customerId = Customer.seItem.id;
        var rc = reservationsId + "," + customerId;
        var index = layer.open({
            type: 2,
            title: '特殊退款',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/refund/to_specialRefund/' + rc
        });
        this.layerIndex = index;
    }
};

Customer.addSpecialRefund = function () {
    var customerId = $("#customerId").val();
    var reservationsId = $("#reservationsId").val();
    var refundMoney = $('#refundMoney').val();
    var remarks = $('#remarks').val();
    var refundsType = $('#refundsType').val();
    if (refundMoney == null || refundMoney == "") {
        alert("请输入退款金额！");
        return
    }
    if (remarks == null || remarks == "") {
        alert("请输入备注！");
        return
    }
    if (!(/^[0-9]{1}\d{0,6}(\.\d{1,2})?$/.test(refundMoney))) {
        alert("请输入正确金额！");
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/refund/addSpecialRefund",
        type: "post",
        data: {
            "customerId": customerId,
            "reservationsId": reservationsId,
            "remarks": remarks,
            "refundsType": refundsType,
            "refundMoney": refundMoney
        },
        success: function (data) {
            Feng.success("操作成功!");
            window.parent.Customer.table.refresh();
            Customer.close();
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
}

Customer.addSpecialSupplement = function () {
    var customerId = $("#customerId").val();
    var reservationsId = $("#reservationsId").val();
    var supplementMoney = $('#supplementMoney').val();
    var remarks = $('#remarks').val();
    if (supplementMoney == null || supplementMoney == "") {
        alert("请输入补费金额！");
        return
    }
    if (remarks == null || remarks == "") {
        alert("请输入备注！");
        return
    }
    if (!(/^[0-9]{1}\d{0,6}(\.\d{1,2})?$/.test(supplementMoney))) {
        alert("请输入正确金额！");
        return;
    }
    $.ajax({
        url: Feng.ctxPath + "/recharge/addSpecialSupplement",
        type: "post",
        data: {
            "customerId": customerId,
            "reservationsId": reservationsId,
            "remarks": remarks,
            "supplementMoney": supplementMoney
        },
        success: function (data) {
            Feng.success("操作成功!");
            window.parent.Customer.table.refresh();
            Customer.close();
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
}

Customer.close = function () {
    // parent.layer.close(window.parent.Customer.layerIndex);
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}

Customer.openRefund = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '添加退款',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/refund/to_refund/' + Customer.seItem.id
        });
        this.layerIndex = index;
    }
};

Customer.openNoRevisit = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '成交操作',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/openNoRevisit/' + reservationsId
    });
    this.layerIndex = index;
};

Customer.uploadCustomer = function () {
    var index = layer.open({
        type: 2,
        title: '批量上传',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/customer_import/'
    });
    this.layerIndex = index;
};

Customer.openRevisitRecord = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_revisitRecord/' + reservationsId
    });
    this.layerIndex = index;
};

Customer.revisitOperation = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '回访操作',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_revisitOperation/' + reservationsId
    });
    this.layerIndex = index;
};

/**
 * 检查是否选中
 */
Customer.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Customer.seItem = selected[0];
        return true;
    }
};

/**
 * 打开重新咨詢
 */
Customer.openReconsulting = function (id) {
    var index = layer.open({
        type: 2,
        title: '再次到店咨詢',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_reconsulting/' + id
    });
    this.layerIndex = index;
};

/**
 * 点击预约客户
 */
Customer.openAddNature = function () {
    var index = layer.open({
        type: 2,
        title: '添加到店客户',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_nature_courtyard_add/' + document.getElementById("customerPhone").value
    });
    this.layerIndex = index;
};

Customer.openAddNatures = function () {
    var index = layer.open({
        type: 2,
        title: '添加到店客户',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_nature_courtyard_addd/' + document.getElementById("customerPhone").value
    });
    this.layerIndex = index;
};

/**
 * 打开查看到店客户详情
 */
Customer.openCustomerDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '到店客户详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/customer/customer_update/' + Customer.seItem.id
        });
        this.layerIndex = index;
    }
};

Customer.openCustomerDetails = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/reservations_details/' + reservationsId
    });
    this.layerIndex = index;
};

Customer.openCustomerDetailss = function (id) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/customer_details/' + id
    });
    this.layerIndex = index;
};

/**
 * 作废预约客户
 */
Customer.openToVoid = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '作废备注',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/customer/openToVoid/' + Customer.seItem.id
        });
    }
};

/**
 * 统计总人数
 */
Customer.total = function () {
    var startArrivalTime = $("#startArrivalTime").val();  //到诊开始时间
    var endArrivalTime = $("#endArrivalTime").val();   //到诊结束时间

    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }

    var dealStatus = $("#dealStatus").val(); //成交状态
    var value = $('#appointmentPayService').val();
    var appointmentPayService = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                appointmentPayService += value[i];
            } else {
                appointmentPayService += value[i] + ",";
            }
        }
    }
    var reach = $("#reach").val();
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + "/customer/total",
        data: {
            appointmentPayService: appointmentPayService,
            startArrivalTime: startArrivalTime,
            endArrivalTime: endArrivalTime,
            oneChannelValue: strOne,
            twoChannelValue: strtwo,
            thrChannelValue: strthr,
            reach: reach,
            dealStatus: dealStatus
        },
        dataType: "json",
        success: function (data) {
            $("#total").html(data[0].countNum);//总人数
            $("#first").html(data[1].countNum);//初到
            $("#firstjieya").html(data[2].countNum);//初到洁牙
            $("#firstZhiliao").html(data[3].countNum);//初治
            $("#two").html(data[4].countNum);//复到
            $("#twojieya").html(data[5].countNum);//复到洁牙
            $("#twoZhiliao").html(data[6].countNum);//复到初治
            $("#wash").html(data[7].countNum);//流失
            $("#again").html(data[8].countNum);//再消

            $("#totalMoney").html(data[0].actualAccountBalanceNum);//总金额
            $("#firstMoney").html(data[1].actualAccountBalanceNum);//初到金额
            $("#firstjieyaMoney").html(data[2].actualAccountBalanceNum);//初到洁牙金额
            $("#firstZhiliaoMoney").html(data[3].actualAccountBalanceNum);//初治金额
            $("#twoMoney").html(data[4].actualAccountBalanceNum);//复到金额
            $("#twojieyaMoney").html(data[5].actualAccountBalanceNum);//复到洁牙金额
            $("#twoZhiliaoMoney").html(data[6].actualAccountBalanceNum);//复到初治金额
            $("#washMoney").html(data[7].actualAccountBalanceNum);//流失金额
            $("#againMoney").html(data[8].actualAccountBalanceNum);//再消金额

        }
    });
}

//总人数数据详情
Customer.totalNumber = function () {
    document.getElementById("customerStatus").value = "";
    document.getElementById("xcustomerStatus").value = "";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//到诊开始时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//到诊结束时间
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;
    queryData['dealStatus'] = $("#dealStatus").val();//成交状态
    queryData['reach'] = $("#reach").val();
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    queryData['customerStatus'] = ""; //加入客户状态，总人数
    queryData['xcustomerStatus'] = ""; //加入客户状态，总人数
    Customer.table.refresh({query: queryData});
};

//初到数据详情
Customer.firstNumbers = function () {
    // document.getElementById("customerStatus").value = "新客首次";
    document.getElementById("xcustomerStatus").value = "初到";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    // queryData['customerStatus'] = "新客首次";//加入客户状态，新客首次
    queryData['xcustomerStatus'] = "'初到','初治','流失'";//加入客户状态，初到
    Customer.table.refresh({query: queryData});
};

//初到洁牙数据详情
Customer.firstjieyaNumber = function () {
    // document.getElementById("customerStatus").value = "新客二次";
    document.getElementById("xcustomerStatus").value = "初到洁牙";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    // queryData['customerStatus'] = "新客二次";//加入客户状态，新客二次
    queryData['xcustomerStatus'] = "'初到洁牙'";//加入客户状态，新客二次
    Customer.table.refresh({query: queryData});
};

//初治数据详情
Customer.firstZhiliaoNumber = function () {
    // document.getElementById("customerStatus").value = "老客";
    document.getElementById("xcustomerStatus").value = "初治";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    // queryData['customerStatus'] = "老客";//加入客户状态，老客
    queryData['xcustomerStatus'] = "'初治'";//加入客户状态，老客
    Customer.table.refresh({query: queryData});
};

//复到数据详情
Customer.twoNumber = function () {
    // document.getElementById("customerStatus").value = "复诊";
    document.getElementById("xcustomerStatus").value = "复到";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    // queryData['customerStatus'] = "复诊";//加入客户状态，复诊
    queryData['xcustomerStatus'] = "'复到','复到初治'";//加入客户状态，复诊
    Customer.table.refresh({query: queryData});
};

//复到洁牙数据详情
Customer.twojieyaNumber = function () {
    // document.getElementById("customerStatus").value = "复诊";
    document.getElementById("xcustomerStatus").value = "复到洁牙";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    // queryData['customerStatus'] = "复诊";//加入客户状态，复诊
    queryData['xcustomerStatus'] = "'复到洁牙'";//加入客户状态，复诊
    Customer.table.refresh({query: queryData});
};

//复到初治数据详情
Customer.twoZhiliaoNumber = function () {
    // document.getElementById("customerStatus").value = "复诊";
    document.getElementById("xcustomerStatus").value = "复到初治";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    // queryData['customerStatus'] = "复诊";//加入客户状态，复诊
    queryData['xcustomerStatus'] = "'复到初治'";//加入客户状态，复诊
    Customer.table.refresh({query: queryData});
};

//流失数据详情
Customer.washNumber = function () {
    // document.getElementById("customerStatus").value = "复诊";
    document.getElementById("xcustomerStatus").value = "流失";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    // queryData['customerStatus'] = "复诊";//加入客户状态，复诊
    queryData['xcustomerStatus'] = "'流失'";//加入客户状态，复诊
    Customer.table.refresh({query: queryData});
};

//再消数据详情
Customer.againNumber = function () {
    // document.getElementById("customerStatus").value = "复诊";
    document.getElementById("xcustomerStatus").value = "再消";
    var queryData = {};
    queryData['startArrivalTime'] = $("#startArrivalTime").val();//开始到店时间
    queryData['endArrivalTime'] = $("#endArrivalTime").val();//结束到店时间
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['reach'] = $("#reach").val();
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    // queryData['customerStatus'] = "复诊";//加入客户状态，复诊
    queryData['xcustomerStatus'] = "'再消'";//加入客户状态，复诊
    Customer.table.refresh({query: queryData});
};


/**
 * 查询预约客户列表
 */
Customer.inquire = function () {
    Customer.search();
};

Customer.search = function () {
    Customer.table.refresh({query: Customer.formParams()});
    Customer.total();
};

Customer.backVisitSearch = function () {
    Customer.table.refresh({query: Customer.formParamsS()});
};

// var parseParam = function (param, key) {
//     var paramStr = "";
//     if (param instanceof String || param instanceof Number || param instanceof Boolean) {
//         paramStr += "&" + key + "=" + param;
//     } else {
//         $.each(param, function (i) {
//             var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
//             paramStr += '&' + parseParam(this, k);
//         });
//     }
//     return paramStr.substr(1);
// };
var parseParam = function (param) {
    var paramStr = "";

    $.each(param, function (i) {
        paramStr += '&' + getSingleData(param, i);
    });
    return paramStr.substr(1);
};

var getSingleData = function (param, key) {
    return key + "=" + param[key];
};


Customer.downLoad = function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['fieldTc'] = $("#fieldTc").val();
    queryData['dealStatus'] = $("#dealStatus").val();

    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
            for (var i = 0; i < valueOne.length; i++) {
                if (i == (valueOne.length - 1)) {
                    strOne += valueOne[i];
                } else {
                    strOne += valueOne[i] + ",";
                }
            }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
            for (var i = 0; i < valuetwo.length; i++) {
                if (i == (valuetwo.length - 1)) {
                    strtwo += valuetwo[i];
                } else {
                    strtwo += valuetwo[i] + ",";
                }
            }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
            for (var i = 0; i < valuethr.length; i++) {
                if (i == (valuethr.length - 1)) {
                    strthr += valuethr[i];
                } else {
                    strthr += valuethr[i] + ",";
                }
            }
    }
    queryData['thrChannel'] = strthr;
    queryData['backVisit'] = $("#backVisit").val();
    queryData['customerStatus'] = $("#customerStatus").val();
    queryData['xcustomerStatus'] = $("#xcustomerStatus").val();
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    var param = parseParam(queryData);
    location.href = Feng.ctxPath + '/customer/customerExport?' + param;
}

Customer.formParamsS = function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['customerName'] = $("#customerName").val();
    queryData['customerPhone'] = $("#customerPhone").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['reservations'] = $("#reservations").val();
    queryData['startRevisitTime'] = $("#startRevisitTime").val();
    queryData['endRevisitTime'] = $("#endRevisitTime").val();
    queryData['isReturnVisit'] = $("#isReturnVisit").val();
    queryData['fieldTc'] = $("#fieldTc").val();
    queryData['doctor'] = $("#doctor").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['customerStatus'] = $("#customerStatus").val();
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;
    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;
    document.getElementById("backVisit").value = "1";
    queryData['backVisit'] = "1";
    return queryData;
}

Customer.resetSearch = function () {
    $("#reach").val("");
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#appointmentPayService").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("请选择");
    $("#twoChannel").val("请选择");
    $("#thrChannel").val("请选择");
    // document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    // document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Customer.search();
};

Customer.reservationMatching = function () {
    var customerPhone = $('#customerPhone').val();
    var str = customerPhone.replace(/(^\s*)|(\s*$)/g, "");
    var customerName = $('#customerName').val();
    var pn;
    if (!(/^\d{5,13}$/).test(str)) {
        alert("电话为5到13位的数字，请重新输入...");
        return;
    }
    if (customerPhone == null || customerPhone == "") {
        alert("请输入电话号码！");
        return;
    }
    var index = layer.open({
        type: 2,
        title: '预约客户电话匹配',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/customer/to_reservation_matching/' + customerPhone
    });
    this.layerIndex = index;
};

/*
导入预约查询明细
 */
Customer.inputInfo = function () {
    var index = layer.open({
        type: 2,
        title: '批量上传',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/recharge/customerInfo_import/'
    });
    this.layerIndex = index;
};

Customer.todayNew = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#appointmentPayService").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    document.getElementById("customerStatus").value = "新客首次"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Customer.search();
};

Customer.todayDeal = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#appointmentPayService").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    document.getElementById("dealStatus").value = "已成交"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Customer.search();
};

Customer.todayNoDeal = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#appointmentPayService").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    document.getElementById("dealStatus").value = "未成交"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Customer.search();
};

Customer.monthDeal = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#appointmentPayService").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    var totalDay = (new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0)).getDate();
    document.getElementById("dealStatus").value = "已成交"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + "01 00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + totalDay + " " + "23:59:59";
    Customer.search();
};

Customer.monthNoDeal = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#appointmentPayService").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#dealStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    var totalDay = (new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0)).getDate();
    document.getElementById("dealStatus").value = "未成交"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + "01 00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + totalDay + " " + "23:59:59";
    Customer.search();
};

Customer.monthNew = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#appointmentPayService").val("");
    $("#fieldTc").val("");
    $("#doctor").val("");
    $("#dealStatus").val("");
    $("#customerStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    var totalDay = (new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0)).getDate();
    document.getElementById("customerStatus").value = "新客首次"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + "01 00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + totalDay + " " + "23:59:59";
    Customer.search();
};

Customer.monthReview = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#appointmentPayService").val("");
    $("#doctor").val("");
    $("#dealStatus").val("");
    $("#customerStatus").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    var totalDay = (new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0)).getDate();
    document.getElementById("customerStatus").value = "复诊"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + "01 00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + totalDay + " " + "23:59:59";
    Customer.search();
};

Customer.todayReview = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservations").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#isReturnVisit").val("");
    $("#fieldTc").val("");
    $("#dealStatus").val("");
    $("#doctor").val("");
    $("#customerStatus").val("");
    $("#appointmentPayService").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    document.getElementById("customerStatus").value = "复诊"
    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Customer.search();
};


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Customer.formParams = function () {
    var queryData = {};
    queryData['reach'] = $("#reach").val();
    queryData['customerName'] = $("#customerName").val();
    queryData['customerPhone'] = $("#customerPhone").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['reservations'] = $("#reservations").val();
    queryData['startRevisitTime'] = $("#startRevisitTime").val();
    queryData['endRevisitTime'] = $("#endRevisitTime").val();
    queryData['isReturnVisit'] = $("#isReturnVisit").val();
    queryData['fieldTc'] = $("#fieldTc").val();
    queryData['doctor'] = $("#doctor").val();
    queryData['dealStatus'] = $("#dealStatus").val();
    queryData['customerStatus'] = $("#customerStatus").val();
    var valueOne = $('#oneChannel').val();
    var strOne = "";
    if (valueOne != null && valueOne != "") {
        for (var i = 0; i < valueOne.length; i++) {
            if (i == (valueOne.length - 1)) {
                strOne += valueOne[i];
            } else {
                strOne += valueOne[i] + ",";
            }
        }
    }
    queryData['oneChannel'] = strOne;

    var valuetwo = $('#twoChannel').val();
    var strtwo = "";
    if (valuetwo != null && valuetwo != "") {
        for (var i = 0; i < valuetwo.length; i++) {
            if (i == (valuetwo.length - 1)) {
                strtwo += valuetwo[i];
            } else {
                strtwo += valuetwo[i] + ",";
            }
        }
    }
    queryData['twoChannel'] = strtwo;

    var valuethr = $('#thrChannel').val();
    var strthr = "";
    if (valuethr != null && valuethr != "") {
        for (var i = 0; i < valuethr.length; i++) {
            if (i == (valuethr.length - 1)) {
                strthr += valuethr[i];
            } else {
                strthr += valuethr[i] + ",";
            }
        }
    }
    queryData['thrChannel'] = strthr;

    var value = $('#appointmentPayService').val();
    var str = "";
    if (value != null && value != "") {
        for (var i = 0; i < value.length; i++) {
            if (i == (value.length - 1)) {
                str += value[i];
            } else {
                str += value[i] + ",";
            }
        }
    }
    queryData['appointmentPayService'] = str;

    document.getElementById("backVisit").value = "";
    queryData['backVisit'] = "";
    return queryData;
}

$("#oneChannel").change(function () {
    Customer.search();
});
$("#twoChannel").change(function () {
    Customer.search();
});
$("#thrChannel").change(function () {
    Customer.search();
});

$(function () {
    //初始化下拉TC列表
    $.post(Feng.ctxPath + "/tc/getLists", function (data) {
        var txt = '<option value="">--请选择现场TC--</option>';
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].tcName + '">' + data[i].tcName + '</option>';
        }
        document.getElementById('fieldTc').innerHTML = txt;
        //状态单选
        var seletetcName = $('#tcNameValue').val();
        if (seletetcName != "") {
            $("#tcName option[value=" + seletetcName + "]").attr("selected", "selected");
        }
    }, "json");


    document.getElementById("startArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";


    //采用定时器监听 时间内容是否变化
    var startArrivalTimeTwo = $("#startArrivalTime").val();
    var endArrivalTimeTwo = $("#endArrivalTime").val();

    var oldOneChannelValue = $("#oneChannel").val();
    var oldTwoChannelValue = $("#twoChannel").val();
    var oldThrChannelValue = $("#thrChannel").val();
    // var oldAppointmentPayServiceValue = $("#appointmentPayService").val();
    setInterval(
        function () {//定时执行方法内容
            if ($("#startArrivalTime").val() != startArrivalTimeTwo || $("#endArrivalTime").val() != endArrivalTimeTwo) {//如果时间发生变化，就触发查询事件
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                startArrivalTimeTwo = $("#startArrivalTime").val();
                endArrivalTimeTwo = $("#endArrivalTime").val();
            }
            /*if ($("#appointmentPayService").val() != oldAppointmentPayServiceValue || $("#appointmentPayService").val() != oldAppointmentPayServiceValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldAppointmentPayServiceValue = $("#appointmentPayService").val();
            }*/
            /*if ($("#oneChannel").val() != oldOneChannelValue || $("#oneChannel").val() != oldOneChannelValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldOneChannelValue = $("#oneChannel").val();
            }
            if ($("#twoChannel").val() != oldTwoChannelValue || $("#twoChannel").val() != oldTwoChannelValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldTwoChannelValue = $("#twoChannel").val();
            }
            if ($("#thrChannel").val() != oldThrChannelValue || $("#thrChannel").val() != oldThrChannelValue) {
                Customer.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldThrChannelValue = $("#thrChannel").val();
            }*/

        }, 500);


    var defaultColunms = Customer.initColumn();
    var table = new BSTable(Customer.id, "/customer/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Customer.formParams());
    Customer.table = table.init();
    Customer.search();

    var menuName = $("#menuName").val();
    $.ajax({
        url: Feng.ctxPath + "/reservation/reservation_initialization",
        type: "post",
        data: {
            "menuName": menuName
        },
        success: function (data) {
            if(data != ""){
                var item = data.listx1.split("，");
                for(var i = 0 ; i < item.length ; i++){
                    $('#CustomerTable').bootstrapTable('hideColumn', item[i]);
                }
            }
        }
    });
});
